//
//  ViewController.m
//  26-Masonry
//
//  Created by dllo on 16/8/18.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import "Masonry.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 使用Masonry不用给初始frame
    UIView *view = [UIView new];
    // 添加约束前先添加到父视图上
    [self.view addSubview:view];
    view.backgroundColor = [UIColor cyanColor];
    // 设置该视图的约束
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        
        
    }];
    UIView *view_blue = [UIView new];
    view_blue.backgroundColor = [UIColor blueColor];
    [view addSubview:view_blue];
    [view_blue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(100);
        make.center.mas_equalTo(0);
        make.width.mas_equalTo(view).multipliedBy(0.5f);
//        make.centerXWithinMargins.mas_equalTo(view);
//        make.centerYWithinMargins.mas_equalTo(0);
    }];
    UIView *view_green = [UIView new];
    view_green.backgroundColor = [UIColor greenColor];
    [view addSubview:view_green];
    [view_green mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(view_blue);
        make.centerX.mas_equalTo(view_blue);
        make.top.mas_equalTo(view_blue.mas_bottom).mas_offset(10);
        
    }];
    UIView *redView = [UIView new];
    redView.backgroundColor = [UIColor redColor];
    [self.view addSubview:redView];
    [redView makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(50);
        make.centerX.equalTo(view);
        make.centerY.equalTo(view).multipliedBy(3 / 2.0f);
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
